Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn with stacklevel=2 to show caller of deprecation #3136

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

hugovk
Copy link
Contributor

@hugovk hugovk commented Mar 5, 2024

Summary

With httpx==0.27.0, I'm getting deprecation warnings like:

  /Users/hugo/my-project/.tox/py312/.venv/lib/python3.12/site-packages/httpx/_client.py:680: DeprecationWarning: The 'app' shortcut is now deprecated. Use the explicit style 'transport=WSGITransport(app=...)' instead.
    warnings.warn(message, DeprecationWarning)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

This points to where the deprecated code is in HTTPX and isn't actionable for me.

Instead, if would be more helpful to point to where the deprecated code is being called from, so I can fix my code (or report to the library).

Adding stacklevel=2 gives:

  /Users/hugo/my-project/.tox/py312/.venv/lib/python3.12/site-packages/litestar/testing/client/sync_client.py:77: DeprecationWarning: The 'app' shortcut is now deprecated. Use the explicit style 'transport=WSGITransport(app=...)' instead.
    Client.__init__(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

(Aha, so Litestar needs fixing! And they've already fixed and released: litestar-org/litestar#3140, I just need to update 👍)


Digging a big deeper, I see there used to be a helper function in httpx/_utils.py:

def warn_deprecated(message: str) -> None:  # pragma: nocover	
    warnings.warn(message, DeprecationWarning, stacklevel=2)	

It was introduced in #963, and removed in #1597.

Should we add it back?

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • [n/a?] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [n/a?] I've updated the documentation accordingly.

@hugovk
Copy link
Contributor Author

hugovk commented Oct 17, 2024

Oops, didn't mean to close this, it was autoclosed when I reset my master back to upstream :)

@hugovk hugovk reopened this Oct 17, 2024
@tomchristie
Copy link
Member

Thanks @hugovk - I think a number of these are removed from the version-1.0 branch.
Should this PR be retargeted?

@hugovk hugovk changed the base branch from master to version-1.0 October 17, 2024 14:45
@hugovk
Copy link
Contributor Author

hugovk commented Oct 17, 2024

Nice, all but three have been removed. I've rebased on version-1.0 and retargeted the version-1.0 branch.

@tomchristie
Copy link
Member

Thanks Hugo. ☺️

@tomchristie tomchristie merged commit 8bceb60 into encode:version-1.0 Oct 17, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants